package com.yzdmw.toutiao.wheeldisk.data;

import com.yzdmw.toutiao.R;
import com.yzdmw.toutiao.model.News;
import com.yzdmw.toutiao.model.Response;
import com.yzdmw.toutiao.service.NetworkService;
import com.yzdmw.toutiao.service.NewsService;

import java.util.List;

import io.reactivex.rxjava3.core.Observable;

public class WheeldiskRepository {

    private static volatile WheeldiskRepository instance;
    private final NewsService newsService;

    private WheeldiskRepository() {
        this.newsService = NetworkService.getInstance().getNewsService();
    }

    public static WheeldiskRepository getInstance() {
        if (instance == null) {
            instance = new WheeldiskRepository();
        }
        return instance;
    }

    public Observable<Response<List<News>>> publicTypeNews(String type, int page){
        return newsService.publicTypeNews(type,page)
                .onErrorReturn(err-> new Response<>(false, R.string.internal_server_error, null));
    }
}